$(document).ready(function() {
    var MaxNumOfPlayers = 6,
        MinNumOfPlayers = 3,
        whatAction = 0,
        inactivityInterval = 0,
        intervalID = 0;
    	roomNumber = 0;
    var browserPlayer = "";
        $statusLabel = $('#statusLabel');
    
    function getURLParameter(name) {
        return decodeURI(
            (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
        );
    }
    
    function yourfunction() 
    { 
    	browserPlayer=getURLParameter("browserPlayer");
    	urlAction =getURLParameter("whatAction");
    	if (urlAction != null && urlAction != "null" && whatAction == 0)
		{
    		whatAction = parseInt(urlAction);
		}
    	if(urlAction != null && urlAction != "null" && 
    			window.location.href.indexOf("Finish") > -1)
    	{
    		whatAction = parseInt(urlAction);
	    }
    	$.post("Timer",{browserPlayer:browserPlayer, whatAction:whatAction}, function(data)
		{
    		var array = JSON.parse(data);
    		browserPlayer=getURLParameter("browserPlayer");
    		var currentPlayer = array[0].currentPlayer;
    		
    		if (currentPlayer != null && currentPlayer == browserPlayer)
			{
    			inactivityInterval++;
    			if (inactivityInterval > 30)
				{
    				 $.post("Retire", {retiredPlayer:browserPlayer} , function(responseJson){
    					 
    					 
    					 
    					 if (browserPlayer != array[i].player)
        				 {
        					$("#infoMessage")[0].innerHTML = array[i].player + " did not respond for a long time and got kicked out!";
        				 }
    					 else
    					 {
    						 $("#infoMessage")[0].innerHTML = "You did not respond for a long time and got kicked out!";
    					 }
    					 
    					 if (responseJson.onePlayerLeft)
    	        			{
    	        				$('<input>').attr({
    	            			    type: 'hidden',
    	            			    value: 'lost',
    	            			    name: 'reason'
    	            			}).appendTo("#finish");
    	        				$('<input>').attr({
    	     	    			    type: 'hidden',
    	     	    			    value: 0,
    	     	    			    name: 'whatAction'
    	     	    			}).appendTo("#finish");
    	            			$("#finish").submit();
    	        			}
    				 });
    				
				}
			}
    		
    		 for (var i=1, len=array.length; i < len; i++) 
    		 {
    			 var executer = array[i].player;
    			 browserPlayer=getURLParameter("browserPlayer");
    			 switch(array[i].code)
    			 {
    			 case "join":   
    				 $.post("RemoveActions", {playerName:array[i].player}, function()
    						 {
    							
    						 });
    				 var wait = array[i].waitformore;
    				 
					 $("#infoMessage")[0].innerHTML = array[i].message;
					 
					 $('input:radio').prop('disabled', true);
					 
					 if (wait == 0)
					 {
						 $("#infoMessage")[0].innerHTML += "\nAll players have joined! game can now start. ";
						 
						 if (browserPlayer == currentPlayer)
	    				 {
	    					 $('input:radio').prop('disabled', false);
	    				 }
					 }
					 
					 
						 $.post("Cards", {playerName:browserPlayer}, function(responseJson)
						 {
							 $("#weaponsCards")[0].innerHTML = responseJson.weaponsCards;
							 $("#charactersCards")[0].innerHTML = responseJson.charactersCards;
							 $("#roomsCards")[0].innerHTML = responseJson.roomsCards;
						 });
					 
					 
					 if (array[i].lastPlayer == browserPlayer && wait == 0 && array[i].currentPlayerType == "COMPUTER")
						{
							 $.post("ComputerPlay");
						}
					 
					 $.post("Player", {roomNumber:roomNumber}, function(jsonRes)
					 {
						$("#playersList")[0].innerHTML = jsonRes.playerList;
					 });
					 
					
    			   break;
    			 case "move":
    				 if (executer != browserPlayer)
					 {
    					 $("#infoMessage")[0].innerHTML = array[i].message;
					 }
    				 break;
    			 case "win":
    				 $('<input>').attr({
    	    			    type: 'hidden',
    	    			    value: 'winner',
    	    			    name: 'reason'
    	    			}).appendTo("#finish");
    	    			
    				 $('<input>').attr({
  	    			    type: 'hidden',
  	    			    value: 0,
  	    			    name: 'whatAction'
  	    			}).appendTo("#finish");
    				 
    				 $('<input>').attr({
 	    			    type: 'hidden',
 	    			    value: browserPlayer,
 	    			    name: 'browserPlayer'
 	    			}).appendTo("#finish");
    				 
    	    			$("#finish").submit();

    				 break;
    			 case "endTurn":
    				 
    				 
    				 
    				 $.post("Player", {roomNumber:roomNumber, newPlayer:array[i].playerNew}, function(jsonRes)
					 {
						$("#playerName")[0].innerHTML = jsonRes.html;
						$("#playersList")[0].innerHTML = jsonRes.playerList;
						roomNumber = jsonRes.roomNumber;
					 });
    				 
    				 
    				 if (browserPlayer != array[i].playerNew)
    				 {
    					 $("#infoMessage")[0].innerHTML = array[i].message;
	    				 $("#weaponGuess").val($("#weaponGuess option:first").val());
	    				 $("#charGuess").val($("#charGuess option:first").val());
	    				 $("#roomGuess").val($("#roomGuess option:first").val());
	    			    
	    				 $('input:radio').prop('disabled', true);
	    				 $('input:radio').prop('checked', false);
	    			     $('#weaponGuess').prop('disabled', true);
	    				 $('#charGuess').prop('disabled', true);
	    				 $('#roomGuess').prop('disabled', true);
	    				 $('#rollDice').prop('disabled', true);
	    				 $('#execute').prop('disabled', true);
	    				 $('#endTurn').prop('disabled', true);
	    			    
	    				 $("#contradictCards")[0].innerHTML = "";
    				 }
    				 else
    				 {
    					 $("#infoMessage")[0].innerHTML = "it is your turn. choose your action please";
    					 $("#weaponGuess").val($("#weaponGuess option:first").val());
	    				 $("#charGuess").val($("#charGuess option:first").val());
	    				 $("#roomGuess").val($("#roomGuess option:first").val());
	    			    
	    				 $('input:radio').prop('disabled', false);
	    				 $('input:radio').prop('checked', false);
	    			     $('#weaponGuess').prop('disabled', true);
	    				 $('#charGuess').prop('disabled', true);
	    				 $('#roomGuess').prop('disabled', true);
	    				 $('#rollDice').prop('disabled', true);
	    				 $('#execute').prop('disabled', true);
	    				 $('#endTurn').prop('disabled', true);
	    			    
	    				 $("#contradictCards")[0].innerHTML = "";
    				 }
    				 
    				 break;
    			 case "lose":
    				 $('<input>').attr({
    	    			    type: 'hidden',
    	    			    value: 'lost',
    	    			    name: 'reason'
    	    			}).appendTo("#finish");
    				 
    				 $('<input>').attr({
 	    			    type: 'hidden',
 	    			    value: 0,
 	    			    name: 'whatAction'
 	    			}).appendTo("#finish");
    				 
    				 $('<input>').attr({
 	    			    type: 'hidden',
 	    			    value: browserPlayer,
 	    			    name: 'browserPlayer'
 	    			}).appendTo("#finish");
    				 
    	    			$("#finish").submit();

    				 break;
    			 case "retire":
    				 if (browserPlayer != array[i].player)
    				 {
    					$("#infoMessage")[0].innerHTML = array[i].message;
    				 }
    				 
    				 if (!array[i].hasMorePlayers)
					 {
    					 $('<input>').attr({
     	    			    type: 'hidden',
     	    			    value: 'lost',
     	    			    name: 'reason'
     	    			}).appendTo("#finish");
     	    			
    					 $('<input>').attr({
      	    			    type: 'hidden',
      	    			    value: 0,
      	    			    name: 'whatAction'
      	    			}).appendTo("#finish");
    					 
	     				 $('<input>').attr({
	  	    			    type: 'hidden',
	  	    			    value: browserPlayer,
	  	    			    name: 'browserPlayer'
	  	    			}).appendTo("#finish");
     				 
     	    			$("#finish").submit();
					 }
    				 
    				 $.post("Player", {roomNumber:roomNumber}, function(jsonRes)
    						 {
    							$("#playersList")[0].innerHTML = jsonRes.playerList;
    						 });
    				 break;
    			 case "disqualified":
    				 $("#infoMessage")[0].innerHTML = array[i].message;
    				 if (!array[i].hasMorePlayers)
					 {
    					 $('<input>').attr({
     	    			    type: 'hidden',
     	    			    value: 'lost',
     	    			    name: 'reason'
     	    			}).appendTo("#finish");
     	    			
    					 $('<input>').attr({
    	 	    			    type: 'hidden',
    	 	    			    value: 0,
    	 	    			    name: 'whatAction'
    	 	    			}).appendTo("#finish");
    					 
	     				 $('<input>').attr({
	  	    			    type: 'hidden',
	  	    			    value: browserPlayer,
	  	    			    name: 'browserPlayer'
	  	    			}).appendTo("#finish");
     				 
     	    			$("#finish").submit();
					 }
    				 else
    				 {
    					 
    					 if ((array[i].playerType == null || array[i].playerType != "COMPUTER") && browserPlayer == array[i].player)
    					 {
        						 $("#infoMessage")[0].innerHTML = " I am sorry your guess is wrong and you are out of the game!";
        						 $('input:radio').prop('disabled', true);
        	    		    	 $('#weaponGuess').prop('disabled', true);
        	    				 $('#charGuess').prop('disabled', true);
        	    				 $('#roomGuess').prop('disabled', true);
        	    				 $('#rollDice').prop('disabled', true);
        	    				 $('#execute').prop('disabled', true);
        						 $('#endTurn').prop('disabled', false);
    					 }
    					 else
    				     {
    						 $("#infoMessage")[0].innerHTML = array[i].message;
    				     }
    					 
    				 }
    				 $.post("Player", {roomNumber:roomNumber}, function(jsonRes)
    						 {
    							$("#playersList")[0].innerHTML = jsonRes.playerList;
    						 });
    				 break;	 
    			 case "assumeOneCardRes":
    				 
    				 if (executer == browserPlayer)
					 {
    					 $("#infoMessage")[0].innerHTML = "Your guess is wrong! " +array[i].contPlayer + " " + "contradicted you! you can see it on the right side of the screen";
    					 $("#contradictCards")[0].innerHTML = array[i].content;
    					 $('#endTurn').prop('disabled', false);
					 }
    				 else if (array[i].contPlayer == browserPlayer)
    				 {
    					 $("#infoMessage")[0].innerHTML =  "You are the first to have one contradicting card, you can see it on the right side of the screen. You are showing it to " + executer;
    					 $("#contradictCards")[0].innerHTML = array[i].content;
    				 }
    				 else 
    				 {
    					 $("#infoMessage")[0].innerHTML = array[i].message;
    				 }
    				 
    				 break;
    			 case "contradict":
    				 
    				 $('input:radio').prop('disabled', true);
    		    	 $('#weaponGuess').prop('disabled', true);
    				 $('#charGuess').prop('disabled', true);
    				 $('#roomGuess').prop('disabled', true);
    				 $('#rollDice').prop('disabled', true);
    				 $('#execute').prop('disabled', true);
    				 
    				 if ((array[i].playerType == null || array[i].playerType != "COMPUTER") && array[i].player == browserPlayer)
					 {
    					 $("#infoMessage")[0].innerHTML = array[i].contPlayer + " " + "contradicted you!";
    					 $("#contradictCards")[0].innerHTML = array[i].content;
    					 $('#endTurn').prop('disabled', false);
					 }
    				 else if (array[i].contPlayer == browserPlayer)
    				 {
    					 $("#infoMessage")[0].innerHTML = "You have successfully contradicted! ";
    				 }
    				 else 
    				 {
    					 $("#infoMessage")[0].innerHTML = array[i].message;
    				 }
    				 
					
    				 break;
    			 case "assumeManyCardsRes":
    				 
    				 $('input:radio').prop('disabled', true);
    		    	 $('#weaponGuess').prop('disabled', true);
    				 $('#charGuess').prop('disabled', true);
    				 $('#roomGuess').prop('disabled', true);
    				 $('#rollDice').prop('disabled', true);
    				 $('#execute').prop('disabled', true);
    				 $('#endTurn').prop('disabled', true);
    				 
    				 if (executer == browserPlayer)
					 {
    					 $("#infoMessage")[0].innerHTML = "Your guess is wrong! wait to see the contradicting card";
					 }
    				 else if (array[i].contPlayer == browserPlayer)
					 {
    					 $("#infoMessage")[0].innerHTML = executer  + " made an assumption, please choose a contradicting card.";
    					 $("#contradictCards")[0].innerHTML = array[i].content;
					 }
    				 else
					 {
    					 $("#infoMessage")[0].innerHTML = array[i].message;
					 }
    				 break;
    			 case "assumeNoRes":
    				 
    				 $('input:radio').prop('disabled', true);
    		    	 $('#weaponGuess').prop('disabled', true);
    				 $('#charGuess').prop('disabled', true);
    				 $('#roomGuess').prop('disabled', true);
    				 $('#rollDice').prop('disabled', true);
    				 $('#execute').prop('disabled', true);
    				 
    				 if ((array[i].playerType == null || array[i].playerType != "COMPUTER") && array[i].player == browserPlayer)
					 {
    					 $("#infoMessage")[0].innerHTML = "No one showed you a contradicting card";
    					 $('#endTurn').prop('disabled', false);
					 }
    				 else
					 {
    					 $("#infoMessage")[0].innerHTML = array[i].message;
					 }
    				 
    				 break;
    			 case "compCorridor":
    				 $("#infoMessage")[0].innerHTML = array[i].message;
    				 break;
    			 case "restart":
    				whatAction = 1;
    				var browserPlayer=getURLParameter("browserPlayer");
    				
					 $.post("Cards", {playerName:browserPlayer}, function(responseJson)
					 {
						 $("#weaponsCards")[0].innerHTML = responseJson.weaponsCards;
						 $("#charactersCards")[0].innerHTML = responseJson.charactersCards;
						 $("#roomsCards")[0].innerHTML = responseJson.roomsCards;
					 });
    				
					 if (currentPlayer == browserPlayer)
					 {
						 $('input:radio').prop('disabled', false);
					 }
					 
					 window.location = "/ClueWeb/CreateGame?browserPlayer="+browserPlayer+"&whatAction=1";
					 
					 /*
    				 $.post("Join", {browserPlayer:browserPlayer} , function(data)
					 {
					 jsRes = JSON.parse(data);
					 if (jsRes.toMove == "yes")
						 {
 					 		window.location = "/ClueWeb/CreateGame?browserPlayer="+browserPlayer;    						 
						 }

		            });
    				 */
	     		    break;
    			 case "start":
    				 $("#infoMessage")[0].innerHTML = array[i].message;
    				 break;
    			 default:
    			     break;
    			 }

		        whatAction++;
		        inactivityInterval=0;
    		 }
        });
	}
    
    intervalID = window.setInterval(yourfunction, 3500);
	newGameJS = function() {
		
		 $numOfPlayers = $('#numOfPlayers');
		 $playerName = $('#name');
		 $numOfComputerPlayers = $('#numOfComputerPlayers');
	};  
	
    // Submit the players' details
    $('#manual').submit(function(e)
    {
        var isValid = true, 
            errorMessage = "";

        if ($numOfPlayers.val() == null || $numOfPlayers.val() == "")
        {
        	 errorMessage = "Must insert number of players";
             isValid = false;
        }
        else if ($playerName.val() == null || $playerName.val() == "")
        {
        	 errorMessage = "Must insert your name";
             isValid = false;
        }
        else if ($numOfComputerPlayers.val() == null || $numOfComputerPlayers.val() == "")
        {
        	 errorMessage = "Must insert number of computer players";
             isValid = false;
        }
        else if ($numOfPlayers.val() < MinNumOfPlayers) {
            errorMessage = "Must have 3-6 players";
            isValid = false;
        } else if ($numOfPlayers.val() > MaxNumOfPlayers) {
            errorMessage = "Only " + MaxNumOfPlayers + " players are allowed";
            isValid = false;
        } 
        else if (isNaN($numOfPlayers.val()))
        {
        	errorMessage = "Number of players must be a number";
            isValid = false;
        }
        else if (isNaN($numOfComputerPlayers.val()))
        {
        	errorMessage = "Number of computer players must be a number";
            isValid = false;
        }
        else if ($numOfComputerPlayers.val() < 0 || $numOfComputerPlayers.val() >= $numOfPlayers.val())
        {
        	errorMessage = "Number of computer players must be between 0 and ";
        	errorMessage += $numOfPlayers.val() - 1;
            isValid = false;
        }
        // If something was invalid, print message and prevent executing
        if (!isValid) {
            $statusLabel.text(errorMessage);
            e.preventDefault();
        } 
        else 
        {
        	numOfComputerPlayers = $numOfComputerPlayers.val();
        	playerName = $playerName.val();
        	numOfPlayers = $numOfPlayers.val();
            $.post("CreateGame", {numOfComputerPlayers:numOfComputerPlayers, playerName:playerName, numOfPlayers:numOfPlayers} , function(){
            	window.location = "/ClueWeb/CreateGame?browserPlayer="+playerName;
            }); 
        }
        return false;
    });

	// Shows content of rooms when you hover a room
    $("img.image-selector").hover(function () {

    	var hoveredRoom = $(this).attr('id');
        $.post("RoomContent", {hoveredRoom:hoveredRoom} , function(rsJson){
        	var div=$("#roomContent");
        	div.animate({height:'300px',opacity:'0.4'},"slow");
        	
        	data = rsJson.content;
        	$("#roomContent")[0].innerHTML = data;
        	$("#roomName")[0].innerHTML = rsJson.room;
        });  
        
    });
    
    // Shows one card that was chosen after clicking on it
    $(document).on("click", ".card", function () {
    	
    	var contradictCard = $(this).attr('src');
    	var label = $(this).attr('name');
    	var contradictPlayer =  $(this).attr('id');
    		
    	$.post("ContradictCard", {contradictCard:contradictCard, label:label, contradictPlayer:contradictPlayer} , function(responseJson){
        }); 
    });
    
    // Shows the content of a valid room when you hover it
    $("img.validRoom").hover(function () {

    	var hoveredRoom = $(this).attr('id');
        $.post("RoomContent", {hoveredRoom:hoveredRoom} , function(data){
        	$("#roomContent")[0].innerHTML = data;
        }); 
        
    }); 
    
    // Changes the game fields according to the user choice of action in his turn
    $('input:radio').click(function(){
    	
    	var checked = $("input[type=radio]:checked").val();
    	
    	if (checked == "assume")
    	{
    		$("#infoMessage")[0].innerHTML = "You chose to assume, now roll the dice";
    		
			 $('#weaponGuess').prop('disabled', true);
			 $('#charGuess').prop('disabled', true);
			 $('#roomGuess').prop('disabled', true);
			 $('#rollDice').prop('disabled', false);
			 $('#execute').prop('disabled', true);
    	}
    	else if (checked == "accuse")
    	{
    		 $("#infoMessage")[0].innerHTML = "Make your accusation and press execute";
    		 
    		 $('#weaponGuess').prop('disabled', false);
			 $('#charGuess').prop('disabled', false);
			 $('#roomGuess').prop('disabled', false);
			 $('#rollDice').prop('disabled', true);
			 $('#execute').prop('disabled', false);
    	}
    	else
    	{
    		 $("#infoMessage")[0].innerHTML = "If you are sure that you want to retire press execute";
    		
   		 $('#weaponGuess').prop('disabled', true);
		 $('#charGuess').prop('disabled', true);
		 $('#roomGuess').prop('disabled', true);
		 $('#rollDice').prop('disabled', true);
    		
    		 $('#execute').prop('disabled', false);
    	}
    });
    
    // Submits the user's action
	$("#execute").click(function(){
		
		var checked = $("input[type=radio]:checked").val();
	    var weapon = $("#weaponGuess").val();
	    var char = $("#charGuess").val();
	    var room = $("#roomGuess").val();
	    
	    $('input:radio').prop('disabled', true);
   	 	$('#weaponGuess').prop('disabled', true);
		 $('#charGuess').prop('disabled', true);
		 $('#roomGuess').prop('disabled', true);
		 $('#rollDice').prop('disabled', true);
		 $('#execute').prop('disabled', true);
		 
	    
	    $.post("Action", {checked:checked, weapon:weapon, character:char, room:room }, function(data){
	    	
	    });
	    	
	    return false;
	});
	
	// Submits the user's action
	$("#retire").click(function(){
		
	    $('input:radio').prop('disabled', true);
   	 	$('#weaponGuess').prop('disabled', true);
		 $('#charGuess').prop('disabled', true);
		 $('#roomGuess').prop('disabled', true);
		 $('#rollDice').prop('disabled', true);
		 $('#execute').prop('disabled', true);
		 $('#retire').prop('disabled', true);
		 var browserPlayer=getURLParameter("browserPlayer");
		 
	    $.post("Retire", {retiredPlayer:browserPlayer}, function(data){
	    	
	    });
	    	
	    return false;
	});
	
	$("#endTurn").click(function() {endTurn();});
	
	// When press end turn finish the turn and move to the next player
	function endTurn(){
	    
		$('#endTurn').prop('disabled', true);
	    $.post("EndTurn");
	}	    
	    	

	// Roll the dice and show the new number
	$('#rollDice').click(function()
	{
		$("#infoMessage")[0].innerHTML = "Now you can enter a room";
		 $('#weaponGuess').prop('disabled', true);
		 $('#charGuess').prop('disabled', true);
		 $('#roomGuess').prop('disabled', true);
		 $('#rollDice').prop('disabled', true);
		 $('#execute').prop('disabled', true);
		 $('input:radio').prop('disabled', true);
		 $('#endTurn').prop('disabled', true);
		 
		//create a random integer between 0 and 5
		var randomdice=Math.round(Math.random()*5) + 1; 
		$('#dice').attr('src', "images/d"+randomdice+".gif");
		
		var validRoom1 = (roomNumber + randomdice + 16) % 16;
		var validRoom2 = (roomNumber - randomdice + 16) % 16;
		
		for ( var int = 0; int < 16; int++) 
		{
		
			if (int == validRoom1 || int == validRoom2) 
			{
				$('#' + int).removeClass('image-selector');
				$('#' + int).addClass('validRoom');
			}  
			else
			{
				$('#' + int).addClass('image-selector');
				$('#' + int).removeClass('validRoom');
			}
			
		}
	});
	
	// Move player to the room he chose
	$("img.image-selector").click(function()
	{
		var roomID = $(this).attr('id');
		
		if ($(this).attr('name') == 'corridor' && $(this).hasClass('validRoom'))
		{
			$.post("MovePlayer", {roomID:roomID}, function(data){
	         });
			
			 $("#infoMessage")[0].innerHTML = "You can not guess in the corridor. please press end turn";
			 for ( var int = 0; int < 16; int++)
			 {
				$('#' + int).removeClass('validRoom');
			 }
			 $('#weaponGuess').prop('disabled', true);
			 $('#charGuess').prop('disabled', true);
			 $('#roomGuess').prop('disabled', true);
			 $('#rollDice').prop('disabled', true);
			 $('#execute').prop('disabled', true);
			 $('input:radio').prop('disabled', true);
			 $('#endTurn').prop('disabled', false);
		}
		else if ($(this).hasClass('validRoom'))
		{
			
			$.post("MovePlayer", {roomID:roomID}, function(data){
	         });
			 $('#weaponGuess').prop('disabled', false);
			 $('#charGuess').prop('disabled', false);
			 $('#roomGuess').prop('disabled', true);
			 $('#rollDice').prop('disabled', true);
			 $('#execute').prop('disabled', false);
			 $('input:radio').prop('disabled', true);
			 
			 var room = $(this).attr('name');
			 
			 $("#infoMessage")[0].innerHTML = "You have enetered to the " + room + ", \n\r  make your assumption and press execute";
			 
			 $('#roomGuess').val(room);
			 for ( var int = 0; int < 16; int++)
			 {
				$('#' + int).removeClass('validRoom');
			 }
		}
		else
		{
			alert('You can not go in there right now!');
		}
	}); 
	
	// Initializing the game
	loadGame = function(){

		 $('#weaponGuess').prop('disabled', true);
		 $('#charGuess').prop('disabled', true);
		 $('#roomGuess').prop('disabled', true);
		 $('#rollDice').prop('disabled', true);
		 $('#execute').prop('disabled', true);
		 $('input:radio').prop('disabled', true);
		 $('#endTurn').prop('disabled', true);
		 $('#endGame').prop('disabled', true);
		 $.post("Player", {roomNumber:roomNumber}, function(jsonRes){
			 browserPlayer=getURLParameter("browserPlayer");
			 $.post("Cards", {playerName:browserPlayer}, function(responseJson)
					 {
						 $("#weaponsCards")[0].innerHTML = responseJson.weaponsCards;
						 $("#charactersCards")[0].innerHTML = responseJson.charactersCards;
						 $("#roomsCards")[0].innerHTML = responseJson.roomsCards;
					 });
				$("#playerName")[0].innerHTML = jsonRes.html;
				$("#playersList")[0].innerHTML = jsonRes.playerList;
				$("#infoMessage")[0].innerHTML = "Welcome! Waiting for all players...";
	        });

		 
		 //yourfunction();
		 whatAction = 0;
	};
	
	
});

